package team18.yuejian.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import team18.yuejian.Activity.OrderDetailActivity;
import team18.yuejian.R;
import team18.yuejian.bean.OrderBean;

import static team18.yuejian.R.layout.cardview_list;

public class MineListAdapter extends RecyclerView.Adapter<MineListAdapter.ViewHolder> {
    private Context mcontext;
    private List<OrderBean> mLists;
    private int mflag;


    static class ViewHolder extends RecyclerView.ViewHolder{
        CardView cardView;
        LinearLayout mlayout;
        TextView typeTitle,type,operation,name;
        ImageView mPic;

        public ViewHolder(View view){
            super(view);
            cardView = (CardView) view;
            mlayout = view.findViewById(R.id.MineList_LinearLayout);
            typeTitle = view.findViewById(R.id.cardview_order_list_typetitle);
            type = view.findViewById(R.id.cardview_order_list_type);
            operation = view.findViewById(R.id.cardview_order_list_operation);
            mPic = view.findViewById(R.id.cardview_order_list_pic);
            name = view.findViewById(R.id.cardview_order_list_oname);
        }

    }

    public MineListAdapter(List<OrderBean> lists, int flag){
        mLists = lists;
        mflag = flag;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (mcontext == null){
            mcontext = parent.getContext();
        }

        View view = LayoutInflater.from(mcontext).inflate(R.layout.cardview_order_list_item,parent,false);

        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {

        final OrderBean Bean = mLists.get(position);
        int status = Bean.getOstatus();
        if (status==0){
            holder.operation.setText("已下单");
        }else if (status==1){
            holder.operation.setText("已付款");
        }else if (status==1){
            holder.operation.setText("已完成");
        }
        switch (mflag){
            case 1:
                holder.type.setText("活动");
                holder.name.setText(Bean.getAname());
                break;
            case 2:
                holder.type.setText("课程");
                holder.name.setText(Bean.getCsname());
                break;
            case 3:
                holder.type.setText("比赛");
                holder.name.setText(Bean.getMtname());
                break;
        }

        holder.mlayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mcontext,OrderDetailActivity.class);
                intent.putExtra("oid",Bean.getOid());
                intent.putExtra("otid",Bean.getOtid());
                mcontext.startActivity(intent);
            }
        });



    }

    @Override
    public int getItemCount() {
        return mLists.size();
    }


}
